<template>
  <div class="app-container">
    <el-form
      ref="enterpriseSelect"
      :model="enterpriseSelect"
      label-width="80px"
      style="width: 100%"
    >
      <el-row
        v-if="false"
        ::gutter="10"
        type="flex"
        align="middle"
        class="select_box"
      >
        <el-col :xs="10" :sm="10" :md="10" :lg="8" :xl="5">
          <el-form-item
            label="企业名称"
            prop="companyName"
            style="margin-bottom: 0; width: 100%"
          >
            <el-select
              v-model="enterpriseSelect.enterpriseId"
              filterable
              placeholder="请选择企业"
              clearable
              :style="{ width: '100%' }"
            >
              <el-option
                v-for="(item, index) in enterpriseSelect.enterpriseNames"
                :key="index"
                :label="item.companyName"
                :value="item.id"
                :disabled="item.disabled"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>

        <el-col :span="1" class="flex align-center" style="margin-left: 0.5rem">
          <el-form-item label-width="0" style="margin-bottom: 0"
            ><el-button type="primary" @click="enterpriseSearch"
              >搜索</el-button
            ></el-form-item
          >
        </el-col>
      </el-row>
    </el-form>

    <el-row style="margin-top: 2rem">
      <el-col v-if="false" :span="24">
        <div style="font-size: 0.95rem">
          当前企业：{{ enterpriseSelect.enterpriseName }}
          <router-link
            :to="{
              path: '/manageInformation/intellectualEdit',
              query: { id: enterpriseSelect.enterpriseId, isCheck: true }
            }"
            style="margin-left: 0.5rem; color: blue"
            v-if="!btnDisabled"
          >
            查看企业信息
          </router-link>
        </div>
      </el-col>
      <el-col v-if="false" :span="24" class="btn-group">
        <el-button
          :type="btn1"
          size="medium"
          :disabled="btnDisabled"
          round
          @click="changeTab(1)"
          >知识产权总表</el-button
        >
        <el-button
          :type="btn2"
          size="medium"
          :disabled="btnDisabled"
          round
          @click="changeTab(2)"
          >高企规划信息表</el-button
        >
        <el-button
          :type="btn3"
          size="medium"
          :disabled="btnDisabled"
          round
          @click="changeTab(3)"
          >导出</el-button
        >
      </el-col>
      <el-col :span="24" class="tabs-box">
        <el-tabs v-model="activeName" @tab-click="handleClick">
          <el-tab-pane label="知识产权总表" name="1">
            <div
              class="flex align-center"
              style="font-size: 1.1rem; font-weight: bold; color: red"
              v-if="btnDisabled"
            >
              <i class="el-icon-warning"></i>
              <span style="margin-left: 0.375rem">请先选择一家企业</span>
            </div>
            <div v-else>
              <div class="text-center text-bold" style="font-size: 1.4rem">
                知识产权总表
              </div>
              <el-divider></el-divider>
              <!-- 表格 -->
              <table
                style="margin: 1rem 0; width: 100%"
                border="1"
                cellpadding="0"
                cellspacing="0"
              >
                <tbody>
                  <template v-if="typeIdOptions1.length">
                    <template v-for="(item, index) in typeIdOptions1.length">
                      <tr
                        v-if="index % 2 == 0 && index == 0"
                        :key="'typeIdOptions1' + index"
                      >
                        <td :rowspan="Math.ceil(typeIdOptions1.length / 2)">
                          I类
                        </td>
                        <td>{{ typeIdOptions1[index].name }}</td>
                        <td>
                          {{
                            typeIdOptions1[index].count
                              ? typeIdOptions1[index].count
                              : 0
                          }}
                        </td>
                        <td>{{ typeIdOptions1[index + 1].name }}</td>
                        <td>
                          {{
                            typeIdOptions1[index + 1].count
                              ? typeIdOptions1[index + 1].count
                              : 0
                          }}
                        </td>
                      </tr>

                      <tr v-if="index % 2 == 0 && index != 0">
                        <td>{{ typeIdOptions1[index].name }}</td>
                        <td>
                          {{
                            typeIdOptions1[index].count
                              ? typeIdOptions1[index].count
                              : 0
                          }}
                        </td>
                        <template v-if="typeIdOptions1[index + 1]">
                          <td>{{ typeIdOptions1[index + 1].name }}</td>
                          <td>
                            {{
                              typeIdOptions1[index + 1].count
                                ? typeIdOptions1[index + 1].count
                                : 0
                            }}
                          </td>
                        </template>
                        <template v-else>
                          <td></td>
                          <td></td>
                        </template>
                      </tr>
                    </template>
                  </template>

                  <template v-if="typeIdOptions2.length">
                    <template v-for="(item, index) in typeIdOptions2.length">
                      <tr
                        v-if="index % 2 == 0 && index == 0"
                        :key="'typeIdOptions2' + index"
                      >
                        <td :rowspan="Math.ceil(typeIdOptions2.length / 2)">
                          II类
                        </td>
                        <td>{{ typeIdOptions2[index].name }}</td>
                        <td>
                          {{
                            typeIdOptions2[index].count
                              ? typeIdOptions2[index].count
                              : 0
                          }}
                        </td>
                        <td>{{ typeIdOptions2[index + 1].name }}</td>
                        <td>
                          {{
                            typeIdOptions2[index + 1].count
                              ? typeIdOptions2[index + 1].count
                              : 0
                          }}
                        </td>
                      </tr>

                      <tr v-if="index % 2 == 0 && index != 0">
                        <td>{{ typeIdOptions2[index].name }}</td>
                        <td>
                          {{
                            typeIdOptions2[index].count
                              ? typeIdOptions2[index].count
                              : 0
                          }}
                        </td>
                        <template v-if="typeIdOptions2[index + 1]">
                          <td>{{ typeIdOptions2[index + 1].name }}</td>
                          <td>
                            {{
                              typeIdOptions2[index + 1].count
                                ? typeIdOptions2[index + 1].count
                                : 0
                            }}
                          </td>
                        </template>
                        <template v-else>
                          <td></td>
                          <td></td>
                        </template>
                      </tr>
                    </template>
                  </template>
                </tbody>
              </table>
              <!-- END -->

              <el-divider></el-divider>

              <!-- 数据表格 -->
              <el-form
                style="margin-top: 2rem"
                :model="queryParams"
                ref="queryForm"
                :inline="true"
              >
                <el-form-item label="证书号" prop="certificateCode">
                  <el-input
                    v-model="queryParams.certificateCode"
                    placeholder="请输入证书号"
                    clearable
                    size="small"
                    style="width: 240px"
                    @keyup.enter.native="handleQuery"
                  />
                </el-form-item>
                <el-form-item label="类别" prop="typeId">
                  <el-select
                    v-model="queryParams.typeId"
                    placeholder="请选择类别"
                    clearable
                    :style="{ width: '100%' }"
                  >
                    <el-option
                      v-for="(item, index) in typeIdOptions"
                      :key="index"
                      :label="item.name"
                      :value="item.id"
                      :disabled="item.disabled"
                    ></el-option>
                  </el-select>
                </el-form-item>

                <!-- <el-form-item label="专利名" prop="patentName">
                  <el-input
                    v-model="queryParams.patentName"
                    placeholder="请输入专利名"
                    clearable
                    size="small"
                    style="width: 240px"
                    @keyup.enter.native="handleQuery"
                  />
                </el-form-item>

                <el-form-item label="专利号/著作权号" prop="patentNumber">
                  <el-input
                    v-model="queryParams.patentNumber"
                    placeholder="请输入专利号/著作权号"
                    clearable
                    size="small"
                    style="width: 240px"
                    @keyup.enter.native="handleQuery"
                  />
                </el-form-item>
                <el-form-item label="获得方式" prop="method">
                  <el-select
                    v-model="queryParams.method"
                    placeholder="请选择获得方式"
                    clearable
                    :style="{ width: '100%' }"
                  >
                    <el-option
                      v-for="(item, index) in methodOptions"
                      :key="index"
                      :label="item.label"
                      :value="item.value"
                      :disabled="item.disabled"
                    ></el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="授权日期" prop="authorizationTime">
                  <el-date-picker
                    v-model="queryParams.authorizationTime"
                    size="small"
                    style="width: 240px"
                    value-format="yyyy-MM-dd"
                    type="date"
                    placeholder="选择授权日期"
                    align="right"
                  ></el-date-picker>
                </el-form-item> -->

                <el-form-item>
                  <el-button
                    type="primary"
                    icon="el-icon-search"
                    size="mini"
                    @click="handleQuery"
                    >搜索</el-button
                  >
                  <el-button
                    icon="el-icon-refresh"
                    size="mini"
                    @click="resetQuery"
                    >重置</el-button
                  >
                </el-form-item>
              </el-form>

              <el-row ::gutter="10" class="mb8">
                <el-col :span="1.5">
                  <el-button
                    type="primary"
                    icon="el-icon-plus"
                    size="mini"
                    @click="handleAdd"
                    >新增</el-button
                  >

                  <el-button
                    type="danger"
                    icon="el-icon-delete"
                    size="mini"
                    @click="handleDelete"
                    >批量删除</el-button
                  >
                </el-col>
              </el-row>

              <el-table
                v-loading="loading"
                :data="enterpriseList"
                border
                @selection-change="handleSelectionChange"
              >
                <el-table-column type="selection" width="55" align="center" />
                <el-table-column
                  v-if="false"
                  label="ID"
                  prop="id"
                  width="120"
                  align="center"
                />
                <el-table-column
                  label="证书号"
                  prop="certificateCode"
                  width="120"
                  align="center"
                />
                <el-table-column
                  label="类别"
                  prop="typeName"
                  :show-overflow-tooltip="true"
                  width="180"
                  align="center"
                >
                </el-table-column>

                <el-table-column
                  label="专利名"
                  prop="patentName"
                  :show-overflow-tooltip="true"
                  width="240"
                  align="center"
                />

                <el-table-column
                  label="授权日期"
                  prop="authorizationTime"
                  width="180"
                  align="center"
                >
                  <template slot-scope="scope">
                    <span>{{
                      parseTime(scope.row.authorizationTime, "{y}-{m}-{d}")
                    }}</span>
                  </template>
                </el-table-column>
                <el-table-column
                  label="专利号/著作权号"
                  prop="patentNumber"
                  :show-overflow-tooltip="true"
                  width="240"
                  align="center"
                />
                <el-table-column
                  label="获得方式"
                  prop="method"
                  :show-overflow-tooltip="true"
                  width="180"
                  align="center"
                >
                  <template slot-scope="scope">
                    <span>{{
                      scope.row.method == 0
                        ? "自主研发"
                        : scope.row.method == 1
                        ? "并购"
                        : "其他"
                    }}</span>
                  </template>
                </el-table-column>

                <el-table-column
                  label="操作"
                  align="center"
                  class-name="small-padding fixed-width"
                >
                  <template slot-scope="scope">
                    <el-button
                      size="mini"
                      type="text"
                      icon="el-icon-edit"
                      @click="handleCheck(scope.row)"
                      >查看</el-button
                    >
                    <el-button
                      size="mini"
                      type="text"
                      icon="el-icon-edit"
                      @click="handleUpdate(scope.row)"
                      >编辑</el-button
                    >
                    <el-button
                      size="mini"
                      type="text"
                      icon="el-icon-delete"
                      @click="handleDelete(scope.row)"
                    >
                      删除
                    </el-button>
                  </template>
                </el-table-column>
              </el-table>

              <pagination
                v-show="total > 0"
                :autoScroll="false"
                :total="total"
                :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize"
                @pagination="getList"
              />
              <!-- END -->
            </div>
          </el-tab-pane>

          <el-tab-pane label="高企规划信息表" name="2">
            <div
              class="flex align-center"
              style="font-size: 1.1rem; font-weight: bold; color: red"
              v-if="btnDisabled"
            >
              <i class="el-icon-warning"></i>
              <span style="margin-left: 0.375rem">请先选择一家企业</span>
            </div>
            <div v-else>
              <el-form
                ref="enterpriseForm"
                :model="formData"
                :rules="rules"
                size="medium"
                label-width="100px"
                label-position="top"
              >
                <el-row :gutter="15">
                  <el-col :span="12">
                    <el-form-item label="技术领域" prop="fieldId">
                      <!-- <el-select v-model="formData.fieldId" placeholder="请选择技术领域" clearable :style="{ width: '100%' }">
                        <el-option v-for="(item, index) in fieldIdOptions" :key="index" :label="item.label" :value="item.value" :disabled="item.disabled"></el-option>
                      </el-select> -->
                      <el-cascader
                        v-model="formData.fieldId"
                        :options="fieldIdOptions"
                        :props="{ value: 'id', label: 'name', emitPath: false }"
                        :style="{ width: '100%' }"
                        @change="handleChange"
                      ></el-cascader>
                    </el-form-item>
                  </el-col>
                </el-row>

                <div class="el-form-item__label">获得的知识产权数量(件)</div>
                <el-row :gutter="15" class="splabel">
                  <el-col :span="12">
                    <el-form-item label="I类" prop="firstType">
                      <span slot="label">
                        I类
                        <el-popover
                          placement="top-start"
                          title="说明"
                          width="200"
                          trigger="hover"
                          content="发明专利"
                          ><i slot="reference" class="el-icon-question"></i
                        ></el-popover>
                      </span>
                      <el-input
                        type="number"
                        v-model="formData.firstType"
                        placeholder="请输入I类知识产权数量"
                        clearable
                        :style="{ width: '100%' }"
                        :readonly="true"
                      ></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="II类" prop="secondType">
                      <span slot="label">
                        II类
                        <el-popover
                          placement="top-start"
                          title="说明"
                          width="auto"
                          trigger="hover"
                          content="实用新型+软件著作权+外观"
                        >
                          <i slot="reference" class="el-icon-question"></i>
                        </el-popover>
                      </span>
                      <el-input
                        type="number"
                        v-model="formData.secondType"
                        placeholder="请输入II类知识产权数量"
                        clearable
                        :style="{ width: '100%' }"
                        :readonly="true"
                      ></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>

                <div class="el-form-item__label">
                  人力资源情况(人)
                  <el-popover
                    placement="top-start"
                    title="填写说明"
                    width="auto"
                    trigger="hover"
                    content="科研人员占职工总数比例达百分之十"
                  >
                    <i
                      slot="reference"
                      class="el-icon-question"
                      style="margin-left: 0.25rem"
                    ></i>
                  </el-popover>
                </div>
                <el-row :gutter="15" class="splabel">
                  <el-col :span="12">
                    <el-form-item label="职工总数" prop="employeesNum">
                      <el-input
                        type="number"
                        v-model="formData.employeesNum"
                        placeholder="请输入职工总数"
                        clearable
                        :style="{ width: '100%' }"
                      ></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="缴纳社保人数" prop="socialSecurityNum">
                      <el-input
                        type="number"
                        v-model="formData.socialSecurityNum"
                        placeholder="请输入缴纳社保人数"
                        clearable
                        :style="{ width: '100%' }"
                      ></el-input>
                    </el-form-item>
                  </el-col>

                  <el-col :span="24">
                    <span class="scientificNum"
                      >科研人数情况（{{ calcScientificNum }}人）</span
                    >
                  </el-col>
                  <el-col
                    :span="21"
                    class="flex align-center justify-between scientificInfo-box"
                  >
                    <el-form-item
                      label="专科及以下"
                      prop="scientificInfo.num1"
                      class="flex align-center scientificInfo"
                    >
                      <el-input
                        type="number"
                        v-model="formData.scientificInfo.num1"
                        placeholder="0"
                        clearable
                      ></el-input>
                    </el-form-item>
                    <el-form-item
                      label="本科"
                      prop="scientificInfo.num2"
                      class="flex align-center scientificInfo"
                    >
                      <el-input
                        type="number"
                        v-model="formData.scientificInfo.num2"
                        placeholder="0"
                        clearable
                      ></el-input>
                    </el-form-item>
                    <el-form-item
                      label="硕士"
                      prop="scientificInfo.num3"
                      class="flex align-center scientificInfo"
                    >
                      <el-input
                        type="number"
                        v-model="formData.scientificInfo.num3"
                        placeholder="0"
                        clearable
                      ></el-input>
                    </el-form-item>
                    <el-form-item
                      label="博士及以上"
                      prop="scientificInfo.num4"
                      class="flex align-center scientificInfo"
                    >
                      <el-input
                        type="number"
                        v-model="formData.scientificInfo.num4"
                        placeholder="0"
                        clearable
                      ></el-input>
                    </el-form-item>
                  </el-col>

                  <el-col
                    :span="21"
                    class="flex align-center justify-between scientificInfo-box"
                    style="margin-top: -1rem;"
                  >
                    <el-form-item
                      label="初级职称"
                      prop="scientificInfo.num5"
                      class="flex align-center scientificInfo"
                    >
                      <el-input
                        type="number"
                        v-model="formData.scientificInfo.num5"
                        placeholder="0"
                        clearable
                      ></el-input>
                    </el-form-item>
                    <el-form-item
                      label="中级职称"
                      prop="scientificInfo.num6"
                      class="flex align-center scientificInfo"
                    >
                      <el-input
                        type="number"
                        v-model="formData.scientificInfo.num6"
                        placeholder="0"
                        clearable
                      ></el-input>
                    </el-form-item>
                    <el-form-item
                      label="高级职称"
                      prop="scientificInfo.num7"
                      class="flex align-center scientificInfo"
                    >
                      <el-input
                        type="number"
                        v-model="formData.scientificInfo.num7"
                        placeholder="0"
                        clearable
                      ></el-input>
                    </el-form-item>
                    <el-form-item
                      label="其他技术人员"
                      prop="scientificInfo.num8"
                      class="flex align-center scientificInfo"
                    >
                      <el-input
                        type="number"
                        v-model="formData.scientificInfo.num8"
                        placeholder="0"
                        clearable
                      ></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>

                <el-row :gutter="15" style="margin: 2rem 0 1.5rem">
                  <div class="dynamic-form">
                    <el-table
                      ref="tableRef"
                      :data="tableData"
                      size="mini"
                      row-key="id"
                      border
                      highlight-current-row
                      style="width: 100%"
                    >
                      <el-table-column
                        label=""
                        width="auto"
                        prop="year"
                        fixed="left"
                        align="center"
                      >
                        <template slot-scope="scope">
                          <el-date-picker
                            v-model="tableData[scope.$index].yearStr"
                            type="year"
                            placeholder="请选择年份"
                            :picker-options="pickerOptions"
                            format="yyyy"
                            value-format="yyyy"
                            clearable
                            :style="{ width: '100%' }"
                            @change="getYear($event, scope.$index)"
                          ></el-date-picker>
                        </template>
                      </el-table-column>
                      <el-table-column
                        label="净资产"
                        width="auto"
                        align="center"
                      >
                        <template slot="header">
                          净资产
                          <el-popover
                            placement="top-start"
                            title="填写说明"
                            width="auto"
                            trigger="hover"
                            content="财务审计报表中“资产负债表”中的“所有者权益”"
                          >
                            <i slot="reference" class="el-icon-question"></i>
                          </el-popover>
                        </template>
                        <template slot-scope="scope">
                          <el-input
                            type="number"
                            v-model="tableData[scope.$index].firstSum"
                            :readonly="true"
                            placeholder="点击填写季度费用,系统自动计算年度总费用"
                            @focus="showCalc(scope.$index, 0)"
                          ></el-input>
                        </template>
                      </el-table-column>
                      <el-table-column
                        label="销售收入"
                        width="auto"
                        align="center"
                      >
                        <template slot="header">
                          销售收入
                          <el-popover
                            placement="top-start"
                            title="填写说明"
                            width="auto"
                            trigger="hover"
                            content="财务审计报表中“利润表”中的“营业收入”"
                          >
                            <i slot="reference" class="el-icon-question"></i>
                          </el-popover>
                        </template>
                        <template slot-scope="scope">
                          <el-input
                            type="number"
                            v-model="tableData[scope.$index].secondSum"
                            :readonly="true"
                            placeholder="点击填写季度费用,系统自动计算年度总费用"
                            @focus="showCalc(scope.$index, 1)"
                          ></el-input>
                        </template>
                      </el-table-column>
                      <el-table-column
                        label="利润总额"
                        width="auto"
                        align="center"
                      >
                        <template slot="header">
                          利润总额
                          <el-popover
                            placement="top-start"
                            title="填写说明"
                            width="auto"
                            trigger="hover"
                            content="财务审计报表中“利润表”中的“利润总额”"
                          >
                            <i slot="reference" class="el-icon-question"></i>
                          </el-popover>
                        </template>
                        <template slot-scope="scope">
                          <el-input
                            type="number"
                            v-model="tableData[scope.$index].thirdSum"
                            :readonly="true"
                            placeholder="点击填写季度费用,系统自动计算年度总费用"
                            @focus="showCalc(scope.$index, 2)"
                          ></el-input>
                        </template>
                      </el-table-column>

                      <!-- 操作 -->
                      <el-table-column
                        label="操作"
                        width="100"
                        align="center"
                        fixed="right"
                      >
                        <template slot-scope="scope">
                          <el-button
                            type="danger"
                            size="mini"
                            @click="deleteInput(scope.$index, 'tableData')"
                            >删除</el-button
                          >
                        </template>
                      </el-table-column>
                    </el-table>
                    <div
                      class="text-center add-input"
                      @click="addInput('tableData')"
                      v-if="!hideButton"
                    >
                      添加
                    </div>
                    <!-- 弹窗输入数据 -->
                    <el-dialog title="" :visible.sync="dialogVisible">
                      <div class="flex align-center justify-center">
                        <el-form :model="planAssetsForm" style="width: 100%;">
                          <el-form-item
                            label="第一季度"
                            prop="quarter0"
                            style="width: 100%;"
                          >
                            <el-input
                              type="number"
                              v-model.number="planAssetsForm.quarter0"
                              style="width: 100%;"
                            ></el-input>
                          </el-form-item>
                          <el-form-item
                            label="第二季度"
                            prop="quarter1"
                            style="width: 100%;"
                          >
                            <el-input
                              type="number"
                              v-model.number="planAssetsForm.quarter1"
                              style="width: 100%;"
                            ></el-input>
                          </el-form-item>
                          <el-form-item
                            label="第三季度"
                            prop="quarter2"
                            style="width: 100%;"
                          >
                            <el-input
                              type="number"
                              v-model.number="planAssetsForm.quarter2"
                              style="width: 100%;"
                            ></el-input>
                          </el-form-item>
                          <el-form-item
                            label="第四季度"
                            prop="quarter3"
                            style="width: 100%;"
                          >
                            <el-input
                              type="number"
                              v-model.number="planAssetsForm.quarter3"
                              style="width: 100%;"
                            ></el-input>
                          </el-form-item>
                        </el-form>
                      </div>
                      <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogVisible = false"
                          >取 消</el-button
                        >
                        <el-button type="primary" @click="saveCalcResult"
                          >确 定</el-button
                        >
                      </div>
                    </el-dialog>
                  </div>
                </el-row>

                <div class="el-form-item__label">
                  近三年研究开发费用总额(万元)
                </div>
                <el-row :gutter="15" class="splabel">
                  <el-col :span="13">
                    <el-form-item
                      label="近三年研究开发费用总额（万元）"
                      prop="costTotal.code1"
                    >
                      <span slot="label">
                        近三年研究开发费用总额（万元）
                        <el-popover
                          placement="top-start"
                          title="填写说明"
                          width="auto"
                          trigger="hover"
                          content="专项审计报表中三年研发费的总和"
                        >
                          <i slot="reference" class="el-icon-question"></i>
                        </el-popover>
                      </span>
                      <el-input
                        type="number"
                        v-model="formData.costTotal.code1"
                        placeholder="请输入近三年研究开发费用总额（万元）"
                        clearable
                        :style="{ width: '100%' }"
                      ></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="13">
                    <el-form-item
                      label="其中：在中国境内研发费用总额（万元）"
                      prop="costTotal.code2"
                    >
                      <el-input
                        type="number"
                        v-model="formData.costTotal.code2"
                        placeholder="请输入在中国境内研发费用总额（万元）"
                        clearable
                        :style="{ width: '100%' }"
                      ></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="13">
                    <el-form-item
                      label="其中：基础研究投入费用总额（万元）"
                      prop="costTotal.code3"
                    >
                      <span slot="label">
                        其中：基础研究投入费用总额（万元）
                        <el-popover
                          placement="top-start"
                          title="填写说明"
                          width="auto"
                          trigger="hover"
                          content="一般企业应填“0”，高校、科研机构可以不为“0”"
                        >
                          <i slot="reference" class="el-icon-question"></i>
                        </el-popover>
                      </span>
                      <el-input
                        type="number"
                        v-model="formData.costTotal.code3"
                        placeholder="请输入基础研究投入费用总额（万元）"
                        clearable
                        :style="{ width: '100%' }"
                      ></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="15">
                  <el-col :span="12">
                    <el-form-item
                      label="近一年企业总收入（万元）"
                      prop="companyTotal"
                    >
                      <span slot="label">
                        近一年企业总收入（万元）
                        <el-popover
                          placement="top-start"
                          title="填写说明"
                          width="auto"
                          trigger="hover"
                          content="主营业收入+营业外收入-不征税收入，在专项审计报告附注中可以查到"
                        >
                          <i slot="reference" class="el-icon-question"></i>
                        </el-popover>
                      </span>
                      <el-input
                        type="number"
                        v-model="formData.companyTotal"
                        placeholder="请输入近一年企业总收入（万元）"
                        clearable
                        :style="{ width: '100%' }"
                      ></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item
                      label="近一年高新技术产品（服务）收入（万元）"
                      prop="productTotal"
                    >
                      <span slot="label">
                        近一年高新技术产品（服务）收入（万元）
                        <el-popover
                          placement="top-start"
                          title="填写说明"
                          width="auto"
                          trigger="hover"
                          content="在专项审计报告中可以查到"
                        >
                          <i slot="reference" class="el-icon-question"></i>
                        </el-popover>
                      </span>
                      <el-input
                        type="number"
                        v-model="formData.productTotal"
                        placeholder="请输入近一年高新技术产品（服务）收入（万元）"
                        clearable
                        :style="{ width: '100%' }"
                      ></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="开票明细" prop="billingInfo">
                      <el-input
                        v-model="formData.billingInfo"
                        placeholder="请输入开票明细"
                        clearable
                        :style="{ width: '100%' }"
                      ></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="行业类别" prop="industryCategory">
                      <el-input
                        v-model="formData.industryCategory"
                        placeholder="请输入行业类别"
                        clearable
                        :style="{ width: '100%' }"
                      ></el-input>
                      <span style="font-size: 0.75rem; color: red"
                        >*
                        不符合高新认定的行业：贸易，商业服务，房地产开发</span
                      >
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="15">
                  <el-form-item
                    label="申请认定前意念是否发生过重大安全，重大质量或严重环境违法行为"
                    prop="isSafe"
                    style="margin-left: 0.5rem"
                  >
                    <span slot="label">
                      申请认定前意念是否发生过重大安全，重大质量或严重环境违法行为
                      <el-popover
                        placement="top-start"
                        title="填写说明"
                        width="auto"
                        trigger="hover"
                        content="前一年如有重大安全或重大质量事故或严重环境违法行为的，不符合申请条件"
                      >
                        <i slot="reference" class="el-icon-question"></i>
                      </el-popover>
                    </span>
                    <el-radio-group v-model="formData.isSafe" size="medium">
                      <el-radio
                        v-for="(item, index) in majorAccidentOptions"
                        :key="index"
                        :label="item.value"
                        :disabled="item.disabled"
                        >{{ item.label }}</el-radio
                      >
                    </el-radio-group>
                  </el-form-item>
                </el-row>
                <el-row :gutter="15">
                  <el-form-item
                    label="是否签订产学研合作协议"
                    prop="isCooperation"
                    style="margin-left: 0.5rem"
                  >
                    <el-radio-group
                      v-model="formData.isCooperation"
                      size="medium"
                    >
                      <el-radio
                        v-for="(item, index) in majorAccidentOptions"
                        :key="index"
                        :label="item.value"
                        :disabled="item.disabled"
                        >{{ item.label }}</el-radio
                      >
                    </el-radio-group>
                  </el-form-item>
                </el-row>
                <el-row :gutter="15">
                  <el-form-item
                    label="附件"
                    prop="fileList"
                    style="margin-left: 0.5rem"
                  >
                    <el-upload
                      ref="fileList"
                      :file-list="relatedAccessoryfileList"
                      :action="relatedAccessoryAction"
                      :headers="relatedAccessoryHeaders"
                      multiple
                      :before-upload="handleBeforeUpload"
                      :before-remove="handleBeforeRemoveUpload"
                      :on-preview="fileListClick"
                      :on-success="handleSuccessUpload"
                    >
                      <el-button
                        size="small"
                        type="primary"
                        icon="el-icon-upload"
                        >上传文件</el-button
                      >
                      <div slot="tip" class="el-upload__tip">
                        只能上传不超过 10MB 的文件
                      </div>
                    </el-upload>
                  </el-form-item>
                </el-row>
                <el-form-item size="large" style="margin-left: 0.5rem">
                  <el-button type="primary" @click="submitForm">提交</el-button>
                  <el-button @click="resetForm">重置</el-button>
                </el-form-item>
              </el-form>
            </div>
          </el-tab-pane>
        </el-tabs>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { getToken } from "@/utils/auth";
import {
  getCompanyManagerList,
  getTypeListAndCountByCompanyId,
  getCompanyCopyrightTypeList,
  getCompanyPlanByCompanyId,
  getTechnicalFieldList,
  queryCompanyCopyrightList,
  addCompanyPlan,
  updateCompanyPlan,
  deleteCompanyInfo,
  exportConfig
} from "@/api/enterprise/intellectual";

export default {
  name: "Intellectual",
  components: {},
  props: [],
  data() {
    return {
      // 企业选择
      enterpriseSelect: {
        enterpriseId: undefined,
        enterpriseName: undefined,
        enterpriseInfo: undefined,
        enterpriseNames: [
          {
            label: "红谷滩区",
            value: "1"
          }
        ]
      },

      // 按钮风格切换
      btn1: "primary",
      btn2: "",
      btn3: "",
      // 按钮是否可点击
      btnDisabled: true,

      // tabs默认位置
      activeName: "1",

      // 是否是第一次修改企业培育信息表
      isFisrtEdit: false,

      /** 数据表格 */
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 选中数组专利名
      selectPatentName: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 表格数据
      enterpriseList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        certificateCode: undefined,
        patentName: undefined,
        typeId: undefined,
        authorizationTime: undefined,
        patentNumber: undefined,
        method: undefined
      },
      /** END */

      /* 搜索下拉选 */
      /* 类别 */
      typeIdOptions: [
        {
          name: "请选择",
          id: "",
          disabled: true
        }
      ],
      /* 第一类 */
      typeIdOptions1: [],
      /* 第二类 */
      typeIdOptions2: [],
      /* 获得方式 */
      methodOptions: [
        {
          label: "请选择",
          value: "",
          disabled: true
        },
        {
          label: "自主研发",
          value: 0
        },
        {
          label: "并购",
          value: 1
        },
        {
          label: "其他",
          value: 2
        }
      ],
      /* END */

      /** 表单 */
      // 科技人员总数
      scientificNum: 0,
      // 表单内容
      formData: {
        fieldId: undefined,
        firstType: 0,
        secondType: 0,
        employeesNum: undefined,
        socialSecurityNum: undefined,
        scientificInfo: {
          num1: undefined,
          num2: undefined,
          num3: undefined,
          num4: undefined,
          num5: undefined,
          num6: undefined,
          num7: undefined,
          num8: undefined
        },
        costTotal: {
          code1: undefined,
          code2: undefined,
          code3: undefined
        },
        companyTotal: undefined,
        productTotal: undefined,
        billingInfo: undefined,
        industryCategory: undefined,
        isSafe: 0,
        isCooperation: 0,
        fileList: null
      },
      rules: {
        fieldId: [
          {
            required: true,
            message: "请选择技术领域",
            trigger: "change"
          }
        ],
        employeesNum: [
          {
            required: true,
            message: "请输入职工总数",
            trigger: "blur"
          }
        ],
        socialSecurityNum: [
          {
            required: true,
            message: "请输入缴纳社保人数",
            trigger: "blur"
          }
        ],
        costTotal: {
          code1: [
            {
              required: true,
              message: "请输入近三年研究开发费用总额（万元）",
              trigger: "blur"
            }
          ],
          code2: [
            {
              required: true,
              message: "请输入在中国境内研发费用总额（万元）",
              trigger: "blur"
            }
          ],
          code3: [
            {
              required: true,
              message: "请输入基础研究投入费用总额（万元）",
              trigger: "blur"
            }
          ]
        },
        companyTotal: [
          {
            required: true,
            message: "请输入近一年企业总收入（万元）",
            trigger: "blur"
          }
        ],
        productTotal: [
          {
            required: true,
            message: "请输入近一年高新技术产品（服务）收入（万元）",
            trigger: "blur"
          }
        ],
        billingInfo: [
          {
            required: true,
            message: "请输入开票明细",
            trigger: "blur"
          }
        ],
        industryCategory: [
          {
            required: true,
            message: "请输入行业类别",
            trigger: "blur"
          }
        ],
        isSafe: [
          {
            required: true,
            message:
              "申请认定前意念是否发生过重大安全，重大质量或严重环境违法行为不能为空",
            trigger: "change"
          }
        ]
      },

      /** 上传相关参数 */
      relatedAccessoryAction: "http://39.96.64.65:8081/system/upload",
      relatedAccessoryHeaders: {
        Authorization: "Bearer " + getToken()
      },
      relatedAccessoryData: {},
      relatedAccessoryfileList: [],
      /* END */

      fieldIdOptions: [
        {
          label: "选项一",
          value: 1
        },
        {
          label: "选项二",
          value: 2
        }
      ],
      majorAccidentOptions: [
        {
          label: "是",
          value: 1
        },
        {
          label: "否",
          value: 0
        }
      ],

      /** 动态表格 */
      /** 限制年份选择器内的选择范围 */
      pickerOptions: {
        disabledDate(time) {
          let curDate = new Date().getTime();
          let three = 1095 * 24 * 3600 * 1000;
          let threeYear = curDate - three;
          return time.getTime() > Date.now() || time.getTime() < threeYear;
        }
      },

      // 是否隐藏添加按钮
      hideButton: false,
      tableData: [
        {
          id: 1,
          yearStr: "2021",
          firstSum: undefined,
          secondSum: undefined,
          thirdSum: undefined,
          assetsList: [
            {
              year: undefined,
              type: 0,
              quarter: 0,
              total: 0
            },
            {
              year: undefined,
              type: 0,
              quarter: 1,
              total: 0
            },
            {
              year: undefined,
              type: 0,
              quarter: 2,
              total: 0
            },
            {
              year: undefined,
              type: 0,
              quarter: 3,
              total: 0
            },
            {
              year: undefined,
              type: 1,
              quarter: 0,
              total: 0
            },
            {
              year: undefined,
              type: 1,
              quarter: 1,
              total: 0
            },
            {
              year: undefined,
              type: 1,
              quarter: 2,
              total: 0
            },
            {
              year: undefined,
              type: 1,
              quarter: 3,
              total: 0
            },
            {
              year: undefined,
              type: 2,
              quarter: 0,
              total: 0
            },
            {
              year: undefined,
              type: 2,
              quarter: 1,
              total: 0
            },
            {
              year: undefined,
              type: 2,
              quarter: 2,
              total: 0
            },
            {
              year: undefined,
              type: 2,
              quarter: 3,
              total: 0
            }
          ]
        }
      ],
      /** END */
      /** 自定义嵌套表单对话框 */
      dialogVisible: false,
      // 当前选中的数据下表
      planAssetsIndex: undefined,
      // 当前选中的数据类型
      planAssetsType: undefined,
      planAssetsForm: {
        quarter0: undefined,
        quarter1: undefined,
        quarter2: undefined,
        quarter3: undefined
      }
      /** END */
    };
  },
  // 路由守卫监听是从哪里来的
  beforeRouteEnter(to, from, next) {
    next(vm => {
      if (from.name === "HandleInfoInformation") {
        vm.getCompanyList().then(() => {
          vm.enterpriseSearch();
        });
      } else if (from.name === "HandleInfoIntellectual") {
        vm.getList();
      }
    });
  },
  created() {
    this.getCompanyList();
  },
  mounted() {},
  computed: {
    calcScientificNum(formData) {
      return (
        Number(
          this.formData.scientificInfo.num1
            ? this.formData.scientificInfo.num1
            : 0
        ) +
        Number(
          this.formData.scientificInfo.num2
            ? this.formData.scientificInfo.num2
            : 0
        ) +
        Number(
          this.formData.scientificInfo.num3
            ? this.formData.scientificInfo.num3
            : 0
        ) +
        Number(
          this.formData.scientificInfo.num4
            ? this.formData.scientificInfo.num4
            : 0
        ) +
        Number(
          this.formData.scientificInfo.num5
            ? this.formData.scientificInfo.num5
            : 0
        ) +
        Number(
          this.formData.scientificInfo.num6
            ? this.formData.scientificInfo.num6
            : 0
        ) +
        Number(
          this.formData.scientificInfo.num7
            ? this.formData.scientificInfo.num7
            : 0
        ) +
        Number(
          this.formData.scientificInfo.num8
            ? this.formData.scientificInfo.num8
            : 0
        )
      );
    }
  },
  methods: {
    //根据 companyId 获取指定的公司信息
    getAccurateCompany(accruateCompanyId) {
      // let resArr =[]
      // if(this.enterpriseSelect){
      //   resArr = this.enterpriseSelect.filter(item=>{
      //     return item.id !== accruateCompanyId
      //   })
      //   return resArr[0]
      // }
      return accruateCompanyId;
    },

    /** 获取企业列表 */
    getCompanyList() {
      return new Promise((resolve, reject) => {
        getCompanyManagerList(this.queryParams).then(response => {
          this.enterpriseSelect.enterpriseNames = response.data;
          this.enterpriseSearch();
          resolve();
        });
      });
    },
    /** 选择企业 */
    enterpriseSearch() {
      let accurateCompanyId = this.$store.state.user.companyId;
      this.enterpriseSelect.enterpriseId = this.getAccurateCompany(
        accurateCompanyId
      );
      let data = this.enterpriseSelect;
      // this.enterpriseSelect.enterpriseId = this.$store.state.user.companyId;
      // if (this.companyManagerId) {
      //   getCompanyInfo(this.companyManagerId).then(res => {
      //     this.form = res.data;
      //   });
      // }

      // 强制返回第一张表
      this.activeName = "1";
      this.btn1 = "primary";
      this.btn2 = this.btn3 = "";

      if (!data.enterpriseId) {
        this.enterpriseList = [];
        this.btnDisabled = true;
        data.enterpriseName = "";
        data.enterpriseInfo = undefined;
        return;
      } else {
        this.btnDisabled = false;
        data.enterpriseInfo = data.enterpriseNames.filter(
          item => item.id === data.enterpriseId
        )[0];
        sessionStorage.setItem(
          "enterpriseInfo",
          JSON.stringify(data.enterpriseInfo)
        );
        data.enterpriseName = data.enterpriseInfo.companyName;

        // 调用接口展示知识产权分类信息
        this.getCompanyTypeList();
        // TODO 调用接口展示当前企业信息
        this.getList();
      }
    },

    // 获取知识产权分类列表数据
    getCompanyTypeList() {
      getCompanyCopyrightTypeList().then(res => {
        this.typeIdOptions = [this.typeIdOptions[0], ...res.data];
      });

      getTypeListAndCountByCompanyId(this.enterpriseSelect.enterpriseId).then(
        res => {
          let data = res.data;
          this.typeIdOptions1 = data.filter((val, ind) => {
            return val.type === 0;
          });
          this.typeIdOptions2 = data.filter((val, ind) => {
            return val.type === 1;
          });
        }
      );
    },

    /* 企业培育规划表相关 */
    // 获取高企规划信息表
    getCompanyPlan() {
      getCompanyPlanByCompanyId(this.enterpriseSelect.enterpriseId).then(
        res => {
          if (res.data) {
            this.formData = res.data;
            this.formData.costTotal = JSON.parse(res.data.costTotal);
            this.formData.scientificInfo = JSON.parse(res.data.scientificInfo);
            this.tableData = res.data.planAssetsCalculation;
          } else {
            this.isFisrtEdit = true;
          }
        }
      );

      this.getTechnicalFieldList();
    },

    // 获取技术领域数据
    getTechnicalFieldList() {
      getTechnicalFieldList().then(res => {
        this.fieldIdOptions = this.handleTree(res.data);
      });
    },

    // 监听多级联动框的数据变化
    handleChange(value) {},
    /* END */

    // 按钮操作
    changeTab(type) {
      if (type !== 3) {
        this.btn1 = this.btn2 = "";
      }

      switch (type) {
        case 1:
          this.btn1 = "primary";
          this.activeName = "1";
          break;
        case 2:
          this.btn2 = "primary";
          this.activeName = "2";
          this.getCompanyPlan();
          break;
        case 3:
          break;
        default:
          break;
      }
    },

    // tabs操作
    handleClick(tab, event) {
      console.log(tab, event);
    },

    /** 数据表格 */
    /** 查询列表 */
    getList() {
      this.loading = true;
      let obj = Object.assign(
        { companyId: this.enterpriseSelect.enterpriseId },
        this.queryParams
      );

      queryCompanyCopyrightList(obj).then(response => {
        this.enterpriseList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        certificateCode: undefined,
        patentName: undefined,
        typeId: undefined,
        authorizationTime: undefined,
        patentNumber: undefined,
        method: undefined
      };
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id);
      this.selectPatentName = selection.map(item => item.patentName);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$router.push({
        path: "/manageInformation/intellectualEdit"
      });
    },
    /** 查看按钮操作 */
    handleCheck(row) {
      this.$router.push({
        path: "/manageInformation/intellectualEdit",
        query: { id: row.id, isCheck: true }
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      // const roleId = row.roleId || this.ids;
      this.$router.push({
        path: "/manageInformation/intellectualEdit",
        query: { id: row.id }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      let ids = row.id || this.ids;
      const title = row.patentName || this.selectPatentName;
      const creatorId = row.creatorId;
      if (Array.isArray(ids)) {
        ids = ids.join(",");
      }
      this.$confirm('是否确认删除"' + title + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(function() {
          // return deleteCompanyInfo(1, ids);
          return deleteCompanyInfo(ids);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
        .catch(function() {});
    },
    /** END */

    /** 数组筛选
     * 如果没有动态表格内除了id以外没有其他数据则不上传
     **/
    arrayFilter(arr) {
      let mArr = arr;
      let res = [];
      /**
       * 先循环处理，清除掉每个子项内的id
       * 然后将当前年份赋值给每一个子项中
       */
      mArr.forEach((v, k) => {
        // let { id, ...obj } = v;
        v.assetsList.forEach(val => {
          val.year = v.yearStr - 0;
        });
        res[k] = v;
      });
      // 再进行过滤
      res = res.filter((value, index, arr) => {
        return value.firstSum || value.secondSum || value.thirdSum;
      });
      return res;
    },
    /** END */

    /** 表单 */
    submitForm() {
      this.$refs["enterpriseForm"].validate(valid => {
        if (!valid) return;
        // TODO 提交表单
        // 处理年报数据
        let assetsList = [];
        this.tableData = this.arrayFilter(this.tableData);
        this.tableData.forEach((val, key) => {
          assetsList.push(...val.assetsList);
        });

        this.formData.fileArr = this.formData.fileList;
        this.formData.planAssets = assetsList;
        this.formData.companyId = this.enterpriseSelect.enterpriseId;

        let { fileList, ...obj } = this.formData;

        if (this.isFisrtEdit) {
          addCompanyPlan(JSON.stringify(obj)).then(response => {
            this.$message({
              message: response.msg,
              type: "success"
            });
            // 关闭当前标签页并返回上一页
            // this.$store.dispatch('tagsView/delView', this.$route);
            // this.$router.go(-1);
          });
        } else {
          let { planAssetsCalculation, ...obj2 } = obj;
          updateCompanyPlan(JSON.stringify(obj2)).then(response => {
            this.$message({
              message: response.msg,
              type: "success"
            });
          });
        }
      });
    },
    resetForm() {
      this.$refs["enterpriseForm"].resetFields();
    },
    /** 获取年份数据 */
    getYear(val, index) {
      // tableData[index].yearStr = val + '';
    },
    /** 动态表格表单 */
    addInput(tableName) {
      if (tableName === "tableData") {
        if (!this.tableData) this.tableData = [];
        let tableLength = this.tableData.length;
        this.tableData.push({
          id: tableLength + 1,
          yearStr: "2021",
          firstSum: undefined,
          secondSum: undefined,
          thirdSum: undefined,
          assetsList: [
            {
              year: undefined,
              type: 0,
              quarter: 0,
              total: 0
            },
            {
              year: undefined,
              type: 0,
              quarter: 1,
              total: 0
            },
            {
              year: undefined,
              type: 0,
              quarter: 2,
              total: 0
            },
            {
              year: undefined,
              type: 0,
              quarter: 3,
              total: 0
            },
            {
              year: undefined,
              type: 1,
              quarter: 0,
              total: 0
            },
            {
              year: undefined,
              type: 1,
              quarter: 1,
              total: 0
            },
            {
              year: undefined,
              type: 1,
              quarter: 2,
              total: 0
            },
            {
              year: undefined,
              type: 1,
              quarter: 3,
              total: 0
            },
            {
              year: undefined,
              type: 2,
              quarter: 0,
              total: 0
            },
            {
              year: undefined,
              type: 2,
              quarter: 1,
              total: 0
            },
            {
              year: undefined,
              type: 2,
              quarter: 2,
              total: 0
            },
            {
              year: undefined,
              type: 2,
              quarter: 3,
              total: 0
            }
          ]
        });
        tableLength + 1 > 3 ? (this.hideButton = true) : "";
      }
    },
    deleteInput(index, tableName) {
      if (tableName === "tableData") {
        this.tableData.splice(index, 1);
        let tableLength = this.tableData.length;
        for (let i = index; i < tableLength; i++) {
          this.tableData[i].id = this.tableData[i].id - 1;
        }
        tableLength < 4 ? (this.hideButton = false) : "";
      }
    },
    /** END */

    /** 动态表格的资产数据录入 */
    showCalc(index, type) {
      // 赋值
      let targetArr = this.tableData[index];
      targetArr.assetsList.filter((val, ind, arr) => {
        if (val.type == type) {
          switch (Number(val.quarter)) {
            case 0:
              this.planAssetsForm.quarter0 = val.total;
              break;
            case 1:
              this.planAssetsForm.quarter1 = val.total;
              break;
            case 2:
              this.planAssetsForm.quarter2 = val.total;
              break;
            case 3:
              this.planAssetsForm.quarter3 = val.total;
              break;
            default:
              break;
          }
        }
        return;
      });

      this.planAssetsIndex = index;
      this.planAssetsType = type;
      this.dialogVisible = true;
    },
    saveCalcResult() {
      // 先计算总和
      let total =
        Number(
          this.planAssetsForm.quarter0 ? this.planAssetsForm.quarter0 : 0
        ) +
        Number(
          this.planAssetsForm.quarter1 ? this.planAssetsForm.quarter1 : 0
        ) +
        Number(
          this.planAssetsForm.quarter2 ? this.planAssetsForm.quarter2 : 0
        ) +
        Number(this.planAssetsForm.quarter3 ? this.planAssetsForm.quarter3 : 0);

      let targetArr = this.tableData[this.planAssetsIndex];
      targetArr.assetsList.filter((val, ind, arr) => {
        if (val.type == this.planAssetsType) {
          switch (Number(arr[ind].quarter)) {
            case 0:
              arr[ind].total = this.planAssetsForm.quarter0;
              break;
            case 1:
              arr[ind].total = this.planAssetsForm.quarter1;
              break;
            case 2:
              arr[ind].total = this.planAssetsForm.quarter2;
              break;
            case 3:
              arr[ind].total = this.planAssetsForm.quarter3;
              break;
            default:
              break;
          }
        }
        return;
      });
      switch (Number(this.planAssetsType)) {
        case 0:
          targetArr.firstSum = total;
          break;
        case 1:
          targetArr.secondSum = total;
          break;
        case 2:
          targetArr.thirdSum = total;
          break;
        default:
          break;
      }
      // 初始化
      this.planAssetsForm = {
        quarter0: undefined,
        quarter1: undefined,
        quarter2: undefined,
        quarter3: undefined
      };
      this.dialogVisible = false;
    },
    /** END */

    /* 文件上传 */
    // 上传之前的操作
    handleBeforeUpload(file) {
      let isRightSize = file.size / 1024 / 1024 < 10;
      if (!isRightSize) {
        this.$message.error("文件大小超过 10MB");
      }
      this.relatedAccessoryData.name = file.name;
      return isRightSize;
    },
    // 上传成功后的操作
    handleSuccessUpload(res) {
      this.formData.fileList.push(res.data);
    },
    // 删除文件列表之前的操作
    handleBeforeRemoveUpload() {
      this.$alert(`目前不支持文件删除!`);
      return false;
    },
    // 点击文件列表内文件的操作
    fileListClick(file) {
      this.$confirm("请选择对此文件的操作", "操作", {
        distinguishCancelAndClose: true,
        confirmButtonText: "阅读",
        cancelButtonText: "下载",
        type: "info",
        center: true
      })
        .then(() => {
          let fileUrl = file.url; //文件路径
          let suffix = fileUrl.replace(/.+\./, "").toLowerCase();

          if (suffix != "pdf") {
            let url = encodeURIComponent(fileUrl);
            let officeUrl =
              "http://view.officeapps.live.com/op/view.aspx?src=" + url;
            window.open(officeUrl, "_target");
          } else {
            window.open(fileUrl, "_target");
          }
          // let previewUrl = fileUrl + "&fullfilename=" + file.name;
          // window.open(
          //   "http://39.96.64.65:8012/onlinePreview?url=" +
          //     encodeURIComponent(previewUrl)
          // );
        })
        .catch(action => {
          if (action === "cancel") {
            window.open(file.url, "_target");
          }
        });
    }
    /* END */
  }
};
</script>

<style lang="scss" scoped>
/* 分页 */
::v-deep .pagination-container {
  height: 2.125rem;
}

.el-upload__tip {
  line-height: 1.2;
}

.el-divider--horizontal {
  margin: 0.75rem 0 !important;
}

.select_box {
  padding-top: 1rem;
  padding-bottom: 1rem;
  border: 1px solid #eee;
}

.btn-group {
  margin-top: 1rem;
  padding: 1rem;
  border: 1px solid #eee;

  button:not(:first-child) {
    margin-left: 1rem;
  }
}

.tabs-box {
  margin-top: 1rem;
  padding: 1rem;
  height: auto;
  min-height: 60vh;
  border: 1px solid #eee;

  ::v-deep .el-tabs__header {
    display: none;
  }
}

/** table css */
table {
  border: 1px solid #f3f3f3;

  tr,
  td {
    padding: 0.75rem;
    text-align: center;
    border: 1px solid #f3f3f3;
  }
}
/** END */

/** 数据表格 */
::v-deep .el-table--border td:first-child .cell {
  padding-left: 14px;
}
/** END */

/** 表单 */
/** 解决tabs切换后表格底部多出一条线 */
::v-deep .el-table:not(.el-table--scrollable-x) .el-table__fixed-right {
  height: 100% !important;
}
::v-deep .el-table__fixed {
  height: 100% !important;
}
::v-deep .el-table::before {
  z-index: inherit;
}

.el-row {
  margin-left: 0 !important;
  margin-right: 0 !important;
}

.splabel {
  margin-bottom: 1rem;
  padding: 0.5rem 1rem;
  background-color: #fafbfc;
  border: 1px solid #eee;
  border-radius: 0.5rem;
}

/** 科研人员 */
.scientificNum {
  font-size: 15px;
  font-weight: bold;
  color: #606266;
}

.scientificInfo-box {
  ::v-deep .el-form-item--medium .el-form-item__label {
    padding: 0;
    padding-right: 0.75rem;
    width: 6rem;
    text-align: right;
  }

  .scientificInfo {
    margin-top: 1rem;
  }
}
/** END */

.dynamic-form {
  ::v-deep .el-input--medium .el-input__inner {
    cursor: pointer;
  }

  .add-input {
    padding: 0.95rem 0;
    border: 1px solid #dfdfdf;
    border-top: 0;
    cursor: pointer;

    &:hover {
      color: #409eff;
      background-color: #f5f7fa;
    }
  }
}
/** End */
</style>
